﻿namespace Pub.Class
{
    using System;

    public class Decompress : Disposable
    {
        private readonly IDecompress decompress;

        public Decompress()
        {
            if (this.decompress.IsNull())
            {
                this.decompress = (IDecompress) (WebConfig.GetApp("DecompressProviderName") ?? "Pub.Class.SharpZip.Decompress,Pub.Class.SharpZip").LoadClass();
            }
        }

        public Decompress(string classNameAndAssembly)
        {
            if (this.decompress.IsNull())
            {
                this.decompress = (IDecompress) classNameAndAssembly.IfNullOrEmpty("Pub.Class.SharpZip.Decompress,Pub.Class.SharpZip").LoadClass();
            }
        }

        public Decompress(string dllFileName, string className)
        {
            if (this.decompress.IsNull())
            {
                this.decompress = (IDecompress) dllFileName.LoadClass(className);
            }
        }

        public Decompress File(string zipPath, string directory)
        {
            this.decompress.File(zipPath, directory);
            return this;
        }

        public Decompress File(string zipPath, string directory, string password)
        {
            this.decompress.File(zipPath, directory, password);
            return this;
        }

        protected override void InternalDispose()
        {
            base.InternalDispose();
        }
    }
}

